package com.dshore.messagecenter.controller.statistics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dshore.messagecenter.model.system.SysDict;
import com.dshore.messagecenter.service.statistics.MessageService;

@Controller
@RequestMapping("/index")
public class MessageFlowController {
	@Autowired
	private MessageService messageService;
	/**
	 * 返回消息流量统计页面
	 * @return
	 */
	@RequestMapping("/messageFlow")
	public String tomessageFlow() {
		return "statistics/messageFlow";
	}
	
	/**
	 * 获取消息统计页面下拉框中的统计周期
	 * @return
	 */
	@RequestMapping("/getPeriod")
	@ResponseBody
	public List<SysDict> getPeriod() {
		List<SysDict>list=messageService.getPeriod();
		return list;
	}
	
	/**
	 * 依据横坐标为时间查询本日的消息流量
	 * @return
	 */
	@RequestMapping("/getTodayMessage")
	@ResponseBody
	public Map<Object,Object> getMessageByTime() {
		Map<Object,Object> m=messageService.getTodayMessageFlowByTime();
		for(int i=0;i<=9;i++) {
			if(!m.containsKey("0"+i)) {
				m.put("0"+i, 0);
			}
		}
		for(int i=10;i<=24;i++) {
			if(!m.containsKey(i)) {
				m.put(i, 0);
			}
		}
		return m;
	}
	
	/**
	 * 依据主题队列为横坐标查询本日的消息流量
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping("/getTodayMessageByTopic")
	@ResponseBody
	public List<List<Object>>getMessageByTopic(){
		List<List<Object>> list=messageService.getTodayMessageFlowByTopic();
		
		return list;
	}
	
	/**
	 * 根据时间---根据下拉框中option标签的id来查询本日(53)的消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMessageByOptionByTime")
	@ResponseBody
	public Map getMessageByOptionByTime(String id) {
		Map m=getMessageByTime();//调用
		return m;
	}
	
	/**
	 * 根据主题队列---根据下拉框中option标签的id来查询本日(id53)的消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMessageByOptionByTopic")
	@ResponseBody
	public List<List<Object>> getMessageByOptionByTopic(String id) {
		List<List<Object>>list=getMessageByTopic();//调用
		 return list;
	}
	
	/**
	 * 根据主题---根据下拉框中option标签的id来查询近7日(id54)消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMessageByOptionByTopicId54")
	@ResponseBody
	public List<List<Object>> getMessageByOptionByTopicId54(String id) {
		List<Map<String, Object>> list=messageService.getMessageByTopicByOptionId54(id);
		List<Object>topicKey=new ArrayList<>();
		List<Object>topicValue=new ArrayList<>();
		List<List<Object>>li = new ArrayList<List<Object>>() ;
		for (Map<String, Object> map : list) {
			Collection<Object> a=map.values();
			Object[] al=a.toArray();
			topicKey.add(al[0]);
			topicValue.add(al[1]);
		}
		li.add(topicKey);
		li.add(topicValue);
		return li;
	}
	
	/**
	 * 根据时间---根据下拉框中option标签的id来查询近7日(id54)的消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMessageByOptionByTimeId54")
	@ResponseBody
	public List<List<Object>> getMessageByOptionByTimeId54(String id) {
		List<Map<String, Object>> list=messageService.getMessageByOptionByTimeId54(id);
		List<Object>qiriqi=new ArrayList<>();
		List<Object>qirizhi=new ArrayList<>();
		List<List<Object>>li = new ArrayList<List<Object>>() ;
		for (Map<String, Object> map : list) {
			Collection<Object> a=map.values();
			Object[] al=a.toArray();
			qiriqi.add(al[0]);
			qirizhi.add(al[1]);
		}
		li.add(qiriqi);
		li.add(qirizhi);
		return li;
	}
	
	/**
	 * 根据主题---根据下拉框中option标签的id来查询近30日(id55)消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMessageByOptionByTopicId55")
	@ResponseBody
	public List<List<Object>> getMessageByOptionByTopicId55(String id) {
		List<Map<String, Object>> list=messageService.getMessageByTopicByOptionId55(id);
		List<Object>topicKey=new ArrayList<>();
		List<Object>topicValue=new ArrayList<>();
		List<List<Object>>li = new ArrayList<List<Object>>() ;
		for (Map<String, Object> map : list) {
			Collection<Object> a=map.values();
			Object[] al=a.toArray();
			topicKey.add(al[0]);
			topicValue.add(al[1]);
		}
		li.add(topicKey);
		li.add(topicValue);
		return li;
	}
	
	/**
	 * 根据时间---根据下拉框中option标签的id来查询近30日(id55)的消息流量数据
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMessageByOptionByTimeId55")
	@ResponseBody
	public List<List<Object>> getMessageByOptionByTimeId55(String id) {
		List<Map<String, Object>> list=messageService.getMessageByOptionByTimeId55(id);
		List<Object>qiriqi=new ArrayList<>();
		List<Object>qirizhi=new ArrayList<>();
		List<List<Object>>li = new ArrayList<List<Object>>() ;
		for (Map<String, Object> map : list) {
			Collection<Object> a=map.values();
			Object[] al=a.toArray();
			qiriqi.add(al[0]);
			qirizhi.add(al[1]);
		}
		li.add(qiriqi);
		li.add(qirizhi);
		return li;
	}
}
